package com.ysstech.reportworld.controller;


import com.ysstech.common.annotation.YssLog;
import com.ysstech.common.annotation.YssPermissions;
import com.ysstech.common.controller.BaseController;
import com.ysstech.common.util.resultutil.RestResult;
import com.ysstech.common.util.resultutil.ResultGenerator;
import com.ysstech.reportworld.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;

/**
 * 导出zip文件给脚本升级工具使用
 */
@Controller
@Slf4j
@Api(tags = "导出升级工具ZIP文件管理api")
@RequestMapping("/upgradeToolsZip")
public class UpgradeToolsZipController extends BaseController {
    @Autowired
    private UpgradeToolsZipService upgradeToolsZipService;


    /**
     * 获取数据库表的 字段和对应的类型
     *
     * @return
     * @throws Exception
     */
    @YssPermissions(value = {"reportworld:upgradetoolszip"})
    @ApiOperation(value = "导出升级工具ZIP文件生成文件")
    @YssLog(module = "导出升级工具ZIP文件管理", remark = "导出升级工具ZIP文件生成文件")
    @PostMapping(value = "/createFile")
    @ResponseBody
    public RestResult createFile() throws Exception {
        upgradeToolsZipService.createFile();
        return ResultGenerator.getSuccessResult("生成升级所需的文件信息成功！");
    }

    /**
     * 获取数据库表的 字段和对应的类型
     *
     * @return
     * @throws Exception
     */
    @YssPermissions(value = {"reportworld:upgradetoolszip"})
    @ApiOperation(value = "导出升级工具ZIP文件管理生成ZIP")
    @YssLog(module = "导出升级工具ZIP文件管理", remark = "导出升级工具ZIP文件管理生成ZIP")
    @PostMapping(value = "/downloadZipFile")
    @ResponseBody
    public void downloadZipFile(HttpServletResponse response) throws Exception {
        upgradeToolsZipService.downloadZipFile(response);
    }
}
